Skip to main content

Starting Playback

Just Press Play

If using the default Reactional prefab, you can toggle the Autoplay bool in Basic Playback to start playback immediately. However, in most use cases you would want more control of when and how music is played back.

By default, the Basic Playback script will run the Reactional.Setup.LoadBundles()function which populate the ReactionalManager with the tracks and themes available in the project.

After having done that, an asynchronous load of the theme’s assets and the current playlist track, will occur.

When ready, the AllowPlay-flag will be set, and the system will be available.

Below you can see a condensed implementation of a playback script:

public class BasicPlayback : MonoBehaviour
{
[SerializeField] private bool _autoplayTheme;
[SerializeField] private bool _autoplayTrack;

public void Start()
{
if (Reactional.Setup.IsValid)
{
Play();
} else {
Debug.LogWarning("Reactional is not setup correctly. Please check the setup guide.");
}
}

private async void Play()
{
// Reactional.Setup.UpdateBundles(); // Check for new bundles in StreamingAssets

// await Reactional.Setup.LoadBundles(); // Load everything in StreamingAssets
// await Reactional.Setup.LoadBundle("BundleName"); // Load everything in a specific bundle

// await Reactional.Setup.LoadSection("BundleName","Default"); // Load specific section in specific bundle
// await Reactional.Setup.LoadSection(); // Load "Default Section" from inspector, or first defined section in first bundle

// await Reactional.Setup.LoadTheme("BundleName","Default","ThemeName");// Load specific theme in specific bundle
// await Reactional.Setup.LoadTheme("ThemeName") // Find and load specifc theme in any bundle
await Reactional.Setup.LoadTheme(); // Load the first theme defined in first bundle

// await Reactional.Setup.LoadPlaylist("BundleName","Default"); // Load specific playlist in specific bundle
// await Reactional.Setup.LoadPlaylist("Default"); // Find and load specifc playlist in any bundle
await Reactional.Setup.LoadPlaylist(); // Load the first playlist defined in first bundle

// await Reactional.Setup.LoadTrack("BundleName","TrackName"); // Load specific track in specific bundle

if (_autoplayTheme)
Reactional.Playback.Theme.Play();
if (_autoplayTrack)
Reactional.Playback.Playlist.Play();

Reactional.Setup.InitAudio();

Reactional.Playback.MusicSystem.PlaybackAllowed = true;
}
}